﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CobreDireto.net.Serialization
{
    internal class Serializer<T> where T : class
    {
        internal static string Serialize(T o)
        {
            System.Xml.Serialization.XmlSerializer
                serializer
                 = new System.Xml.Serialization.XmlSerializer(o.GetType());

            System.IO.StringWriter sw = new System.IO.StringWriter();
            serializer.Serialize(sw, o);
            sw.Flush();

            return sw.ToString();
        }

        internal static T Deserialize(string str)
        {
            System.Xml.Serialization.XmlSerializer
                           serializer
                            = new System.Xml.Serialization.XmlSerializer(typeof(T));

            System.IO.StringReader sr = new System.IO.StringReader(str);
            T result =  serializer.Deserialize(sr) as T;

            return result;
        }
    }
}
